﻿using System.Data.Objects.DataClasses;
using System.Collections.Generic;
using System;
using UtfprLibrary.EntityFramework.Exceptions;
using UtfprLibrary.EntityFramework.Helpers;

namespace UtfprLibrary.EntityFramework.Extensions {
    public static class EntityObjectExtensions {
        public static List<EntityObject> GetRelatedReferences<T>(this T entity) where T : EntityObject {
            try {
                var entityReferences = EntityHelper.GetEntityReferences(entity);
                return entityReferences;
            } catch (Exception ex) {
                throw new UtfprEFExtensionsException("", ex);
            }
        }

        public static List<object> GetRelatedCollections<T>(this T entity) where T : EntityObject {
            try {
                var entityCollections = EntityCollectionHelper.GetEntityCollections(entity);
                return entityCollections;
            } catch (Exception ex) {
                throw new UtfprEFExtensionsException("", ex);
            }
        }
    }
}